package cn.itcalvin.sncoal.cth.controller;

import cn.itcalvin.sncoal.cth.aspect.LogAnnotation;
import cn.itcalvin.sncoal.cth.aspect.RoleAnnotation;
import cn.itcalvin.sncoal.cth.pojo.common.ReqLong;
import cn.itcalvin.sncoal.cth.pojo.req.news.ReqNewsAdd;
import cn.itcalvin.sncoal.cth.pojo.req.news.ReqNewsList;
import cn.itcalvin.sncoal.cth.pojo.req.news.ReqNewsModify;
import cn.itcalvin.sncoal.cth.pojo.response.news.RespNewsList;
import cn.itcalvin.sncoal.cth.service.InfoNewsService;
import cn.itcalvin.vo.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "新闻管理")
@RestController
@RequestMapping("/api/news")
public class NewsController {

    @Resource
    private InfoNewsService infoNewsService;



    @PostMapping("add")
    @RoleAnnotation(value = "1,3")
    @LogAnnotation(value = "新增新闻")
    @ApiOperation(value = "新增新闻")
    public Message add(@RequestBody @Valid ReqNewsAdd reqNewsAdd){
        return infoNewsService.add(reqNewsAdd);
    }
    @PostMapping("modify")
    @RoleAnnotation(value = "1,3")
    @LogAnnotation(value = "修改新闻")
    @ApiOperation(value = "修改新闻")
    public Message modify(@RequestBody @Valid ReqNewsModify reqNewsModify){
        return infoNewsService.modify(reqNewsModify);
    }
    @PostMapping("delete")
    @RoleAnnotation(value = "1,3")
    @LogAnnotation(value = "删除新闻")
    @ApiOperation(value = "删除新闻")
    public Message delete(@RequestBody @Valid ReqLong reqLong){
        return infoNewsService.delete(reqLong);
    }

    @PostMapping("list")
    @RoleAnnotation(value = "1,3")
    @LogAnnotation(value = "新闻列表-管理员")
    @ApiOperation(value = "新闻列表-管理员")
    public Message<List<RespNewsList>> list(@RequestBody @Valid ReqNewsList reqNewsList){
        return infoNewsService.list(reqNewsList);
    }
    @PostMapping("listShow")
    @LogAnnotation(value = "新闻列表-所有用户")
    @ApiOperation(value = "新闻列表-所有用户")
    public Message<List<RespNewsList>> listShow(@RequestBody @Valid ReqNewsList reqNewsList){
        reqNewsList.setState(2);
        return infoNewsService.list(reqNewsList);
    }

    @PostMapping("details")
    @LogAnnotation(value = "新闻详情",logType = 2)
    @ApiOperation(value = "新闻详情")
    public Message<RespNewsList> details(@RequestBody @Valid ReqLong reqLong){
        return infoNewsService.details(reqLong);
    }

}
